|
|
 |
|
|
|
|
6: 'If the following Select statement is able to handle message
7: 'then the error can be handled by this method
8: Select Case argErrorObj.Number
9: Case eMathErrors.DivByZero
10: sMsg = Division by zero was attempted
11: Case eMathErrors.OverFlow
12: sMsg = Overflow occurred
13: Case eMathErrors.BadCall
14: sMsg = Illegal procedure call
15: End Select
16:
17: MsgBox sMsg, vbExclamation
18: Resume Next ' the Exit Function statement.
19: End Sub
20: Private Enum eMathErrors
21: DivByZero = 11
22: OverFlow = 6
23: BadCall = 5
24: End Enum |
|
|
|
|
|
|
|
|
You could reduce the lines of code in Listing 18.2 as follows: |
|
|
|
|
|
|
|
|
Select Case argErrorObject.Number
Case eMathErrors.DivByZero, eMathErrors.OverFlow, eMathErrors.BadCall
MsgBox argErrorObject.Description, vbExclamation
End Select |
|
|
|
|
|
|
|
|
However, this approach would not make your error-handling subsystem very precise in its treatment. But if your application doesn't require anything beyond what error information Visual Basic provides, then the simplified approach might be preferable. |
|
|
|
|
|
|
|
|
The Purpose of This Subsystem |
|
|
|
|
|
|
|
|
Designing and implementing components in Visual Basic can be a complex undertaking. You must create a useful set of interfaces as well as effective implementation classes and methods. More importantly, your components have to successfully handle errors and exceptions that are bound to occur. In particular, you must plan for the following kinds of errors: |
|
|
|
|
|
|
|
|
Errors that your component traps but allows the client to handle |
|
|
|
|
|
|
|
|
Errors that originate in another component from which your component received and used object references |
|
|
|
|
|
|
|
|
Errors that originate in your component that may have been the result of programmer error or some rule violation that must be enforced by your component |
|
|
|
|
|